import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 *
 * @author
 * @since
 */
public class UserServiceJdkProxy  {
  private static final Logger LOG = LoggerFactory.getLogger(UserServiceImpl.class);
  private Object target;

  public UserServiceJdkProxy(Object obj){
    super();
    target = obj;
  }

  public Object getProxyInstance(){
    return Proxy.newProxyInstance(target.getClass().getClassLoader()
        , target.getClass().getInterfaces()
        , new InvocationHandler() {
          @Override
          public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            LOG.info("事务开始");
            Object obj = method.invoke(target, args);
            LOG.info("事务结束");
            return obj;
          }
        });
  }
}
